//
//  TLCommentsFrame.m
//  Coding_iOS
//
//  Created by taolei-mac on 2017/11/24.
//  Copyright © 2017年 com.lianchuan. All rights reserved.
//

#import "TLCommentsFrame.h"
#import "TLCommentCell.h"
#import "TLTweet.h"
#import "TLComment.h"

@interface TLCommentsFrame()

@end

@implementation TLCommentsFrame

- (void)setTweet:(TLTweet *)tweet
{
    _tweet = tweet;
   
    NSInteger likes = tweet.likes;
    CGFloat likesViewH = 50;
    if(likes <= 0){
        likesViewH = 0;
    }
    self.likesFrame = CGRectMake(15, 0, TLScreenW -30, likesViewH);
    
    NSInteger commentsCount = tweet.comments;
    CGFloat commentsHeight = 0;
    NSInteger visibleCount = 0;
    if(commentsCount > 5){
        
        visibleCount = 5; // 最多显示5条评论
    }else{
        visibleCount = commentsCount;
    }
    for (int i = 0; i < visibleCount; i++) {

        TLComment *comment = tweet.comment_list[i];
        commentsHeight = commentsHeight + [TLCommentCell commemtCellHeightWithCommemt:comment];
        //TLLog(@"%f", commentsHeight);
    }
    if(commentsCount > 5){
        
        commentsHeight += 40.0;
        
       // TLLog(@"========%f", commentsHeight);
    }

    self.commentsFrame = CGRectMake(15, CGRectGetMaxY(self.likesFrame), TLScreenW - 30, commentsHeight);
    
    //计算自己的frame
    CGFloat h = 0;
    if(commentsCount > 0){
        
        h = CGRectGetMaxY(self.commentsFrame) + 10;
    }else{
        
        h = CGRectGetMaxY(self.likesFrame) + 10;
    }
    //TLLog(@"高度----%f", h);
    self.frame = CGRectMake(0, 0, TLScreenW, h);
}

@end
